//
//  TableViewController.m
//  14微博
//
//  Created by apple on 15/8/2.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "TableViewController.h"
#import "LMmicroBlogFrame.h"
#import "LMmicroBlog.h"
#import "LMmicroBlogCell.h"
@interface TableViewController ()

@property (strong, nonatomic) IBOutlet UITableView *tableview;
@property (nonatomic,strong) NSArray *microBlogFrame;
@end

@implementation TableViewController

- (NSArray *)microBlogFrame
{
    if (_microBlogFrame ==nil) {
        NSArray *microBlog = [LMmicroBlog microBlogToList];
        
        NSMutableArray *frames = [NSMutableArray array];
        
        for (LMmicroBlog *blog in microBlog) {
            LMmicroBlogFrame *frame =[[LMmicroBlogFrame alloc] init];
            
            frame.microBlog = blog;
            [frames addObject:frame];
        }
        _microBlogFrame = frames;
        
    }
    return _microBlogFrame;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.dataSource = self;
    self.tableView.delegate  = self;
    
    
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return self.microBlogFrame.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LMmicroBlogCell *cell = [LMmicroBlogCell microBlogCellWithTableView:tableView];
    
    LMmicroBlogFrame *frame = self.microBlogFrame[indexPath.row];
    
    cell.microBlogFrame = frame;
    
    return cell;
}


#pragma  mark -代理自动调节高度

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
       LMmicroBlogFrame *frame = self.microBlogFrame[indexPath.row];
    NSDecimalNumber *myOtherDecimalObj = [[NSDecimalNumber alloc] initWithFloat:frame.rowheight];
    NSLog(@"doubleValue=%6.5f",[myOtherDecimalObj doubleValue]);
     return  frame.rowheight;
}

@end
